package com.chcit.mobile.mvp.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.chcit.mobile.app.base.BaseSupportActivity;
import com.chcit.mobile.app.base.ScanActivity;
import com.chcit.mobile.common.DataKeys;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.chcit.mobile.di.component.DaggerTaskComponent;
import com.chcit.mobile.di.module.TaskModule;
import com.chcit.mobile.mvp.contract.TaskContract;
import com.chcit.mobile.mvp.presenter.TaskPresenter;
import com.chcit.mobile.R;
import me.yokeyword.fragmentation.SupportFragment;

import static com.jess.arms.utils.Preconditions.checkNotNull;


public class TaskActivity extends ScanActivity<TaskPresenter> implements TaskContract.View {

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerTaskComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .taskModule(new TaskModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {

        return R.layout.activity_task; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

        SupportFragment baseFragment = null;
        try {
            baseFragment = (SupportFragment) ((Class<?>)getIntent().getSerializableExtra(DataKeys.FRAGEMNT_NAME.name())).newInstance();
        } catch (Exception e) {
            showMessage(e.getMessage());
            finish();
            return;
        }
        loadRootFragment(R.id.fl_container, baseFragment);

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public Context getActivity() {
        return this;
    }
}
